/**
 * Created by Administrator on 2017/7/3.
 */
var vm = avalon.define({
    $id: 'application',
    name: '',
    phone: '',
    idCard: '',
    birthday: '',
    address: '',
    school: '',
    profession: '',
    education: '',
    startDate1: '',
    company1: '',
    job1: '',
    startDate2: '',
    company2: '',
    job2: '',
    startDate3: '',
    company3: '',
    job3: '',
    jobId: '',
    isResume: false,
    isMale: true,//false为女
    isMarried: true,//false未婚
    uploadSuccess: '请选择文件',
    submit_resume: function () {
        var _basePath = resumeApply_url();
        console.log(_basePath);
        var self = this;
        var education = self.education == '大专' ? '0' : (self.education == '本科' ? '1' : (self.education == '硕士' ? '2' : (self.education == '博士' ? '3' : (self.education == '高中' ? '4' : (self.education == '中专' ? '5' : (self.education == '其他' ? '6':''))))));
        ff.util.submit({
            url: 'recruitmentJob/resumeApply',
            data: {
                jobId: self.jobId,
                name: self.name,
                gender: (self.isMale ? 'Male' : 'female'),
                isMarried: (self.isMarried ? '1' : '0'),
                idcard: self.idCard,
                phone: self.phone,
                birthdayStr: self.birthday,
                address: self.address,
                school: self.school,
                major: self.profession,
                education: education,
                workExperience: {
                    "expList": [
                        {
                            "time": self.startDate1,
                            "companyName": self.company1,
                            "possion": self.job1
                        },
                        {
                            "time": self.startDate2,
                            "companyName": self.company2,
                            "possion": self.job2
                        },
                        {
                            "time": self.startDate3,
                            "companyName": self.company3,
                            "possion": self.job3
                        }
                    ]
                },
                hasResume: self.isResume == false ? 0 : 1
            },
            success: function (res) {
                if (res.resultStatus == 100) {
                    ff.util.show(res.resultData );
                } else {
                    ff.util.show("数据请求失败!");
                }
            }
        });
        /*$.ajax({
         url: _basePath,
         dataType: 'json',
         type:'get',
         data: {
         jobId: self.jobId,
         name: self.name,
         gender: (self.isMale?'Male':'female'),
         isMarried: (self.isMarried?'Male':'female'),
         idcard: self.idCard,
         phone: self.phone,
         birthday: self.birthday,
         address: self.address,
         school: self.school,
         major: '',
         education: '',
         workExperience: {},
         hasResume: self.isResume
         },
         success: function (data, status, xhr) {
         console.log(JSON.stringify(data, null, 4))
         if (data.resultStatus == 100) {
         // vm_recruitment.jobDetail = data.resultData;
         // $('.jobDuties').html(data.resultData.jobDuties);
         } else {
         console.log(data.resultMsg);
         }
         }
         })*/
    },
    selectFile: function (e) {
        var file = e.target.files[0];
        console.log(file);
        uploadByForm(file);
    },
    select_gender: function (index) {
        if (index == 0) {
            this.isMale = false;
        } else if (index == 1) {
            this.isMale = true;
        }
    },
    select_Married: function (index) {
        if (index == 0) {
            this.isMarried = false;
        } else if (index == 1) {
            this.isMarried = true;
        }
    }
})
init()

function init() {
    var id = $.frontEngine.getUrlParameter("id");
    console.log(id);
    vm.jobId = id;
}
function uploadByForm(file) {
    var param = new FormData(); //创建form对象
    //param.append('image',file,file.name);//通过append向form对象添加数据
    param.append('file', file, file.name);//通过append向form对象添加数据

    param.append('fileName', file.name);
    param.append('chunk', '0');//添加form表单中其他数据
    console.log(param.get('file')); //FormData私有类对象，访问不到，可以通过get判断值是否传进去
    var config = {
        headers: {'Content-Type': 'multipart/form-data'}
    };  //添加请求头
    console.log(basePath)
    axios.post(basePath + "site/upload.do", param, config)
        .then(function (response) {
            if (response.data.resultStatus == 100) {
                vm.isResume = true;
                // debugger;
                vm.uploadSuccess = response.data.resultData
            } else {
                vm.uploadSuccess = response.data.resultMsg;
            }
            console.log(response.data);
            /* var res = response.data;
             var src = res.imgPath;*/
            /*vm.businessLicence = src;
             $("#"+imgId).attr("src",src);
             $("#"+imgId).attr("value",src);*/
            // ff.loading.hide();
        });
}
